<?php

echo "Examples to show how to use the api. <BR>";
echo "They show the calling sequence and how to use the returned value <BR><BR>";
/*  Include the API */
require('ac_db.inc.php');

/* Define the credentials for the database instance */

setcredentials("jlh2174","DtnNvvdq", "w4111c.cs.columbia.edu/ADB");

/* make a db instance */
$db = new Db("Proj1", "Part3");

echo "Connected to database @ w4111c.cs.columbia.edu/ADB <BR>";

echo "<BR>1. Example for loginUser<BR>";
$c = "jlh2174@columbia.edu";
$p="Jenny";
$res = $db->loginUser($c,$p);
if ($res) {
	echo "Customer $c is a valid user <BR>";
} else {
	echo "Customer $c is not a valid user <BR>";
}

echo "<BR>2. Example for updatePassword<BR>";
$c = "jlh2174@columbia.edu";
$p = "Columbia3";
$res = $db->updatePassword($c,$p);


echo "<BR>3. Example for getCustomerDetails<BR>";
$c = "jlh2174@columbia.edu";
$res = $db->getCustomerDetails($c);
if ($res) {
	$f = $res['FIRST_NAME'];
	$l = $res['LAST_NAME'];
	echo "First name = $f, Last Name = $l<BR>";
} else {
	echo "Customer $c is not a valid user <BR>";
}

echo "<BR>4. Example for updateUser<BR>";
$c = "jlh2174@columbia.edu";
$l = "Hwang1";
$f = "Jenny1";
$db->updateUser($c, $f, $l);

echo "<BR>5. Example for getPortfolioStocks<BR>";
$c = "jlh2174@columbia.edu";
$res = $db->getPortfolioStocks($c);
if ($res) {
echo "<table border='1'>\n";
echo "<tr><th>Ticker Symbol</th>";
echo "</tr>\n";
foreach ($res as $row) {
	$tk = $row['TICKER_SYMBOL'];
	echo "<tr><td>$tk</td></tr>\n";
}
echo "</table>";
}

echo "<BR>6. Example for getStockName<BR>";
$c = "TGT";
$res = $db->getStockName($c);
if ($res) {
	echo "Ticker $c, company name = $res<BR>";
} else {
	echo "Ticker $c is not in the database <BR>";
}

echo "<BR>7. Example for getCurrentStockValue<BR>";
$c = "TGT";
$res = $db->getCurrentStockValue($c);
if ($res) {
	echo "Ticker $c, value = $res<BR>";
} else {
	echo "Ticker $c is not in the database <BR>";
}

echo "<BR>8. Example for getUserTransactions<BR>";
$c = "jlh2174@columbia.edu";
$res = $db->getUserTransactions($c);
if ($res) {
echo "<table border='1'>\n";
echo "<tr><th>Ticker Symbol</th>";
echo "</tr>\n";
foreach ($res as $row) {
	$tk = $row['TRANSACTION_ID'];
	echo "<tr><td>$tk</td></tr>\n";
}
echo "</table>";
}

echo "<BR>9. Example for getTransactionDetails<BR>";
foreach ($res as $row) {
	$tk = $row['TRANSACTION_ID'];
	$myres = $db->getTransactionDetails($tk);
	$t1 = $myres['TRANSACTION_ID'];
	$t2 = $myres['TXDATE'];
	$t3 = $myres['QUANTITY'];
	$t4 = $myres['PRICE'];
	echo "Transaction Info = $t1, $t2, $t3, $t4 <BR>";
}

echo "<BR>10. Example for getAllStocks<BR>";
$res = $db->getAllStocks();
echo "Tick Symbol = ";
foreach ($res as $row) {
	$t1 = $row['TICKER_SYMBOL'];
	echo "$t1 ";
}
echo "<BR>";

echo "<BR>11. Example for getFullStockInformation<BR>";
$c = "TGT";
$res = $db->getFullStockInformation($c);
echo "Stock Info = ";
foreach ($res as $row) {
	$t1 = $row['TICKER_SYMBOL'];
	$t2 = $row['COMPANY_NAME'];
	$t3 = $row['DAILY_HIGH'];
	echo "$t1, $t2, $t3 ";
}
echo "<BR>";

echo "<BR>12. Example for isValidStock<BR>";
$c = "TGT1";
$res = $db->getFullStockInformation($c);
if ($res) {
	echo "$c is in the database <BR>";
} else {
	echo "$c is not in the database <BR>";
}

echo "<BR>13. Example for createUser<BR>";
$c = "new1@columbia.edu";
$l = "First";
$f = "Last";
// $db->createUser($c, $f, $l);

echo "<BR>14. Example for createStock<BR>";
$c = array("TICKER_SYMBOL"=>"GRPN", "COMPANY_NAME"=>"Groupon, Inc.", "DAILY_HIGH"=>24.74,
	"DAILY_LOW"=>23.68, "CURRENT_VALUE"=>24.27, "DAILY_VOLUME"=>657169, 
	"CLOSE_PRICE"=>24.07, "OPEN_PRICE"=> 24.02);
// $db->createStock($c);

echo "<BR>15. Example for updateStock<BR>";
$c = "DAILY_VOLUME=50000, CLOSE_PRICE=28.77, OPEN_PRICE= 27.02";
$e = "GRPN";
$db->updateStock($e,$c);

?>

